package com.li.Exception;

import com.li.constant.MessageConstant;
import com.li.entity.Result;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MyExceptionHandler implements HandlerExceptionResolver {
    private MessageConstant messageConstant;

    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {

        ModelAndView mv = new ModelAndView();
        if (e instanceof MyException || e instanceof RuntimeException) {
            String message = (String) httpServletRequest.getAttribute("message");
            mv.addObject("message", message);
        }
        return mv;
    }
}
